/**
 *
 */
package com.abel.bigwater.dataserver.model.hgd

import io.netty.buffer.ByteBuf

/**
 * 04 05 3E 4C CC CD 3E 80 00 00 3E 8F 5C 29
 * 类型 通道号 模拟量数据 1 模拟量数据 2 模拟量数据 3
 * A5 0.2 0.25 0.28智慧物联 智慧水务
 *
 * @author Abel
 */
class AnalogChannel(count: Short) : HgdChannel<Float>(HgdChannelType.ANALOG_TYPE, count) {
    /**
     * compute length of bytes.
     */
    override fun bufLength() = 2 + 4 * count

    /* (non-Javadoc)
     * @see com.abel.bigwater.dataserver.model.hgd.HgdChannel#parseBuffer(io.netty.buffer.ByteBuf)
     */
    override fun parseBuffer(buf: ByteBuf): Boolean {
        super.parseBuffer(buf)

        for (i in 1..count) {
            values.add(buf.readFloat())
        }

        return true
    }

    /* (non-Javadoc)
     * @see com.abel.bigwater.dataserver.model.hgd.HgdChannel#pack(io.netty.buffer.ByteBuf)
     */
    override fun pack(buf: ByteBuf): Boolean {
        super.pack(buf)

        for (i in 0 until count) {
            buf.writeFloat(values[i])
        }

        return true
    }

}
